// Company/rencai/rencai.js
const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curNav: 1,
    navTypes:[
      {id: 1, label: '全部人才', type: 1},
      // {id: 2, label: '待面试', type: 2},
      // {id: 3, label: '感兴趣', type: 3},
      // {id: 4, label: '不感兴趣', type: 4},
    ],
    isLoading: false,
    rcList:[],
    search:{
      pageNum: 1,
      pageSize: 10,
      ageBegin: "",
      ageEnd: "",
      education: "",
      experienceBegin: "",
      experienceEnd: "",
      name: "",
      sex: "",
      specialty: "",
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRCList()
  },
  reload(){
    let filterForm = wx.getStorageSync('rc_search')
    filterForm.pageNum = 1
    this.setData({
      rcList: [],
      search: Object.assign({}, this.data.search, filterForm)
    })

    this.getRCList()
  },
  onNavChange(e){
    let navId = e.currentTarget.dataset.id
    this.setData({
      curNav: navId
    })
  },
  toFilter(){
    wx.navigateTo({
      url: '/Company/rcfilter/rcfilter',
    })
  },
  toJianLi(e){
    let { item } = e.currentTarget.dataset
    wx.setStorageSync('jl_header', item.header)
    wx.navigateTo({
      url: '/HomePage/linejianli/linejianli?type=view&uid='+ item.userUid,
    })
  },
  getRCList(){
    let _this = this
    this.setData({ isLoading: true })
    wx.request({
      url: url + 'findPeople/getFindPeopleList',
      header:{ 'Content-Type': 'application/json',},
      data: this.data.search,
      method: "POST",
      success(res){
        _this.setData({ isLoading: false })
        let resData = res.data
        if(resData.code != 200 || !resData.data){
          wx.showToast({
            title: resData.msg,
            icon:'error'
          })
          return
        }
        let rcList = (resData.data.content || []).filter(item => item.id) 
        
        if(_this.data.search.pageNum > 1 && rcList.length === 0){
          wx.showToast({
            title: '到底了~~',
            icon:'none'
          })
          return
        }
        _this.setData({
          rcList: [..._this.data.rcList, ...rcList]
        })
      },
      fail(){
        _this.setData({ isLoading: false })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({ selected: 1 })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.search.pageNum++
    this.setData({
      search: this.data.search
    })
    this.getRCList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})